﻿using Autofac;
using Brc_PaaS.Bll.Account;
using Brc_PaaS.Bll.Apollo;
using Brc_PaaS.Bll.Exceptionless;
using Brc_PaaS.Bll.RabbitMq;
using Brc_PaaS.Bll.Redis;
using Brc_PaaS.Bll.System;
using Brc_PaaS.Core.Apollo.Service;
using Brc_PaaS.Core.Apollo.Service.Implement;
using Brc_PaaS.Core.Exceptionless;
using Brc_PaaS.Core.RabbitMq;
using Brc_PaaS.Dal;
using Microsoft.Extensions.Configuration;

namespace Brc_PaaS.Api.Common
{
    /// <summary>
    /// IOC注入配置类
    /// </summary>
    public class AutofacModule : Autofac.Module
    {
        private IConfiguration Configuration;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="configuration"></param>
        public AutofacModule(IConfiguration configuration)
        {
            Configuration = configuration;
        }
        /// <summary>
        /// 加载配置数据
        /// </summary>
        /// <param name="builder">容器绑定器</param>
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterInstance(Configuration);//注入配置对象
            #region 业务
            builder.RegisterType(typeof(Redis)).As(typeof(IRedis)).InstancePerDependency();
            builder.RegisterType(typeof(Bll.System.System)).As(typeof(ISystem)).InstancePerDependency();
            //.RegisterType(typeof(IAccount)).As(typeof(Account)).InstancePerDependency();
            builder.RegisterType(typeof(Account)).As(typeof(IAccount)).InstancePerDependency();
            builder.RegisterType(typeof(Bll.Apollo.Apollo)).As(typeof(IApollo)).InstancePerDependency();
            builder.RegisterType(typeof(ExceptionlessLog)).As(typeof(IExceptionlessLog)).InstancePerDependency();
            builder.RegisterType(typeof(RabbitMqManager)).As(typeof(IRabbitMqManager)).InstancePerDependency();
            builder.RegisterType(typeof(RabbitMqBasicManager)).As(typeof(IRabbitMqBasicManager)).InstancePerDependency();
            #endregion

            #region 仓储
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerDependency();
            #endregion

            #region Core
            builder.RegisterType(typeof(LogManager)).As(typeof(ILogManager)).InstancePerDependency();
            builder.RegisterType(typeof(ApolloNamespaceService)).As(typeof(IApolloNamespaceService)).InstancePerDependency();
            builder.RegisterType(typeof(ApolloConfigService)).As(typeof(IApolloConfigService)).InstancePerDependency();
            builder.RegisterType(typeof(RabbitMqClient)).As(typeof(IRabbitMqClient)).InstancePerDependency();
            builder.RegisterType(typeof(RabbitMqBasic)).As(typeof(IRabbitMqBasic)).InstancePerDependency();
            #endregion
        }
    }
}
